package com.snopy.sorts.bubble;


/**
 * @author snopy
 * @description:冒泡排序
 * @classname Test2
 * @date 2020/10/19 16:40
 * @email 77912204@qq.com
 */
public class Bubble {

    public static void main(String[] args) {
        int[] arr = {6,5,4,3,2,1};
        System.out.println("初始数组：");
        System.out.println("6 5 4 3 2 1");
        for (int i =0;i<arr.length-1;i++){
               for (int j=0;j<arr.length-i-1;j++){
                    int temp;
                    if (arr[j]>arr[j+1]){
                        temp = arr[j];
                        arr[j] =  arr[j+1];
                        arr[j+1] = temp;
                    }
                }
            System.out.println("第"+(i+1)+"次冒泡：");
            for (int k=0;k<arr.length;k++){
                System.out.print(arr[k]+" ");
            }
            System.out.println();
        }
        for (int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }

    }
}
